package com.ltt.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ‘李天泰’
 * @version 1.0
 * @description: TODO
 * @date 2023/5/1 11:04
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket docket() {
        //添加head参数配置start
        ParameterBuilder tokenPar = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<>();
        tokenPar.name("Authorization").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        pars.add(tokenPar.build());

        // 添加请求头
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .select() // 通过select方法配置如何扫描接口;
                .apis(RequestHandlerSelectors.basePackage("com.ltt.controller"))
                .build()
                .globalOperationParameters(pars);
    }

    // 配置文档信息
    private ApiInfo apiInfo() {
        Contact contact = new Contact("李天泰","yangmaogroup.xyz","1916689406@qq.com");
        return new ApiInfo(
                "BigHouse", // 标题
                "BigHouse后端接口", // 描述
                "v1.0", // 版本
                "yangmaogroup.xyz", // 组织连接
                contact, // 联系人信息
                "Apach 2.0 许可", // 许可
                "许可连接",
                new ArrayList<>()
        );
    }
}
